Page({
  data: {
    serviceTypes: [
      {
        id: 1,
        name: '生活照料',
        icon: '/static/zhyl/生活照料.png',
        bgColor: 'rgba(76, 217, 100, 0.1)'
      },
      {
        id: 2,
        name: '临床护理',
        icon: '/static/zhyl/常用临床护理.png',
        bgColor: 'rgba(90, 120, 255, 0.1)'
      },
      {
        id: 3,
        name: '康复护理',
        icon: '/static/zhyl/康复护理.png',
        bgColor: 'rgba(255, 193, 7, 0.1)'
      },
      {
        id: 4,
        name: '心理关怀',
        icon: '/static/zhyl/心理关怀.png',
        bgColor: 'rgba(255, 59, 48, 0.1)'
      },
      {
        id: 5,
        name: '上门做饭',
        icon: '/static/zhyl/做饭.png',
        bgColor: 'rgba(255, 90, 110, 0.1)'
      },
      {
        id: 6,
        name: '健康管理',
        icon: '/static/zhyl/健康管理.png',
        bgColor: 'rgba(0, 204, 153, 0.1)'
      },
      {
        id: 7,
        name: '陪同就医',
        icon: '/static/zhyl/陪同就医.png',
        bgColor: 'rgba(127, 110, 255, 0.1)'
      },
      {
        id: 8,
        name: '日常清洁',
        icon: '/static/zhyl/日常清洁.png',
        bgColor: 'rgba(255, 181, 86, 0.1)'
      }
    ],
    caregivers: [
      {
        id: 1,
        name: '张护士',
        title: '高级护理师',
        avatar: '/static/zhyl/护理师1.png',
        rating: 4.9
      },
      {
        id: 2,
        name: '李阿姨',
        title: '家政护理员',
        avatar: '/static/zhyl/护理师2.png',
        rating: 4.8
      },
      {
        id: 3,
        name: '王医生',
        title: '康复治疗师',
        avatar: '/static/zhyl/护理师3.png',
        rating: 4.9
      }
    ],
    serviceInfo: [
      {
        id: 1,
        title: '专业认证',
        description: '持证上岗，定期培训',
        icon: '/static/zhyl/专业认证.png'
      },
      {
        id: 2,
        title: '安全保障',
        description: '人身意外保险保障',
        icon: '/static/zhyl/安全保障.png'
      },
      {
        id: 3,
        title: '一键呼叫',
        description: '24小时响应服务',
        icon: '/static/zhyl/一键呼叫.png'
      }
    ],
    countdown: {
      hours: '03',
      minutes: '33',
      seconds: '33'
    },
    discountServices: [
      {
        id: 1,
        title: '康复护理 老年腰肌劳损推拿按摩服务',
        image: '/static/zhyl/按摩服务.png',
        currentPrice: '300',
        originalPrice: '600'
      },
      {
        id: 2,
        title: '康复护理 老年腰肌劳损推拿按摩服务',
        image: '/static/zhyl/按摩服务.png',
        currentPrice: '300',
        originalPrice: '600'
      },
      {
        id: 3,
        title: '康复护理 老年腰肌劳损推拿按摩服务',
        image: '/static/zhyl/按摩服务.png',
        currentPrice: '300',
        originalPrice: '600'
      }
    ],
    recommendServices: [
      {
        id: 1,
        title: '日常清洁 2小时1人急速清洁全程质保',
        image: '/static/zhyl/清洁服务.png',
        price: '300',
        sales: '40'
      }
    ]
  },

  onLoad: function() {
    this.startCountdown()
  },

  // 返回上一页
  goBack: function() {
    const pages = getCurrentPages();
    if (pages.length > 1) {
      wx.navigateBack({
        delta: 1
      });
    } else {
      wx.switchTab({
        url: '/pages/index/index'
      });
    }
  },

  // 搜索输入
  onSearchInput: function(e) {
    this.setData({
      searchText: e.detail.value
    })
  },

  // 搜索确认
  onSearch: function(e) {
    const keyword = e.detail.value || this.data.searchText
    if (keyword.trim()) {
      // 这里实现搜索逻辑
      console.log('搜索关键词：', keyword)
    }
  },

  // 服务类型点击
  onServiceTap: function(e) {
    const serviceType = e.currentTarget.dataset.type
    wx.navigateTo({
      url: `/pages/services/homecare/type/index?id=${serviceType.id}&name=${serviceType.name}`
    })
  },

  // 服务详情点击
  onServiceDetail: function(e) {
    const serviceId = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/services/homecare/detail/index?id=${serviceId}`
    })
  },

  // 开始倒计时
  startCountdown: function() {
    let totalSeconds = 3 * 3600 + 33 * 60 + 33 // 3小时33分33秒
    
    this.countdownTimer = setInterval(() => {
      if (totalSeconds <= 0) {
        clearInterval(this.countdownTimer)
        return
      }

      totalSeconds--
      const hours = Math.floor(totalSeconds / 3600)
      const minutes = Math.floor((totalSeconds % 3600) / 60)
      const seconds = totalSeconds % 60

      this.setData({
        countdown: {
          hours: hours.toString().padStart(2, '0'),
          minutes: minutes.toString().padStart(2, '0'),
          seconds: seconds.toString().padStart(2, '0')
        }
      })
    }, 1000)
  },

  onUnload: function() {
    if (this.countdownTimer) {
      clearInterval(this.countdownTimer)
    }
  },

  // 选择服务类型
  selectServiceType: function(e) {
    const serviceId = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/services/homecare/detail/index?type=${serviceId}`
    })
  },

  // 查看护理人员详情
  viewCaregiver: function(e) {
    const caregiverId = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/services/homecare/caregiver/index?id=${caregiverId}`
    })
  },

  // 开始预约
  startBooking: function() {
    wx.navigateTo({
      url: '/pages/services/homecare/booking/index'
    })
  },

  onShareAppMessage: function() {
    return {
      title: '专业家政护理服务',
      path: '/pages/services/homecare/index'
    }
  }
}) 